import {createRouter, createWebHistory} from 'vue-router'
import config from "@/config"
// import NProgress from 'nprogress'
// import 'nprogress/css/nprogress.css'
import tool from '@/utils/tool';
import systemRouter from './systemRouter';
import transitionExtend from "./extend";
// //系统路由
const routes = systemRouter


let router = createRouter({
  history: createWebHistory(),
  routes: routes
})
router = transitionExtend(router)
// //设置标题
document.title = config.APP_NAME
//
router.beforeEach(async (to, from, next) => {
  // NProgress.start()
  //动态标题
  document.title = to.meta.title ? `${to.meta.title} - ${config.APP_NAME}` : `${config.APP_NAME}`
  let token = tool.data.get("v4TOKEN");

  if(to.path === "/login"){
    //删除路由(替换当前layout路由)
    router.addRoute(routes[0])
    next();
    return false;
  }

  if(!token){
    next({
      path: '/login'
    });
    return false;
  }
  next();
});

router.onError((error) => {
  // NProgress.done();
});

//
export default router
//
